package com.deyang.mycommon.mvp.presenter;

import android.app.Activity;

import com.deyang.mycommon.entity.BaseAdapterTestItem;
import com.deyang.mycommon.mvp.model.BaseAdapterModelImpl;
import com.deyang.mycommon.mvp.model.IBaseAdapterModel;
import com.deyang.mycommon.mvp.mvpcallback.ValueCallBack;
import com.deyang.mycommon.mvp.view.BaseAdapterView;

import java.util.List;

public class BaseAdapterPresenter extends BasePresenter {

    private Activity activity;

    private BaseAdapterView baseAdapterView;
    private IBaseAdapterModel baseAdapterModel;

    public BaseAdapterPresenter(Activity activity,
                                BaseAdapterView baseAdapterView) {
        this.activity = activity;
        this.baseAdapterView = baseAdapterView;
        this.baseAdapterModel = new BaseAdapterModelImpl();
    }

    public List<BaseAdapterTestItem> getAdapterData() {
        return baseAdapterModel.getBaseAdapterItemList();
    }

    @Override
    public void initData() {

        baseAdapterModel.loadData(new ValueCallBack<List<BaseAdapterTestItem>>() {
            @Override
            public void onSuccess(List<BaseAdapterTestItem> data) {
                //在这里取消loading
                //简单数据操作可以在presenter里完成
                baseAdapterModel.getBaseAdapterItemList().addAll(data);
                baseAdapterView.refreshUpdateUI();
            }

            @Override
            public void onFail(String failMsg) {
                baseAdapterView.refreshErro(failMsg);
            }
        });
    }
}
